const http=require('http');

const server=http.createServer((req,res)=>{
    let ip=getClientIp(req);
    res.end(ip);
});

server.listen(4001,'0.0.0.0',()=>{
    console.log('Get client ip@4001',new Date().toLocaleString());
});

function getClientIp(req) {
    return req.headers['x-forwarded-for'] ||
        req.connection.remoteAddress ||
        req.socket.remoteAddress ||
        req.connection.socket.remoteAddress;
}